﻿//********************************************************************************//
//创建日期：<创建日期，2010-08-02>
//创建作者：<王一飞，wangyifei@shanghai3h.com>
//功能说明：YS_SF_ZHICHUXG实体层次
//********************************************************************************//

#region Entity

using System;
using System.Data;
using Entity;
using Oracle.DataAccess.Client;
using Platform.Configuration;
using Platform.Data;

namespace Entity
{
    [Serializable]
    public class YS_SF_ZHICHUXG
    {
        private double? m_db_n_jine;

        private decimal? m_dec_i_chulir;

        private decimal? m_dec_i_feiyongbh;

        private decimal? m_dec_i_jlzt;

        private decimal? m_dec_i_m;

        private decimal? m_dec_i_type;

        private decimal? m_dec_i_y;

        private decimal? m_dec_i_yuanbh;

        private decimal m_dec_i_zhichubh;

        private decimal? m_dec_i_zwny;

        private DateTime? m_DT_d_chuanpiaorq;

        private DateTime? m_DT_d_chulirq;

        private string m_str_s_reason;

        private string m_str_s_yonghuh;

        private string m_str_s_zhandianbh;

        /// <summary>
        ///     主键支出编号
        /// </summary>
        public decimal I_ZHICHUBH
        {
            get { return m_dec_i_zhichubh; }
            set { m_dec_i_zhichubh = value; }
        }

        /// <summary>
        ///     处理人
        /// </summary>
        public decimal? I_CHULIR
        {
            get { return m_dec_i_chulir; }
            set { m_dec_i_chulir = value; }
        }

        /// <summary>
        ///     费用编号
        /// </summary>
        public decimal? I_FEIYONGBH
        {
            get { return m_dec_i_feiyongbh; }
            set { m_dec_i_feiyongbh = value; }
        }

        /// <summary>
        ///     水量年
        /// </summary>
        public decimal? I_Y
        {
            get { return m_dec_i_y; }
            set { m_dec_i_y = value; }
        }

        /// <summary>
        ///     水量月
        /// </summary>
        public decimal? I_M
        {
            get { return m_dec_i_m; }
            set { m_dec_i_m = value; }
        }

        /// <summary>
        ///     科目类型
        /// </summary>
        public decimal? I_TYPE
        {
            get { return m_dec_i_type; }
            set { m_dec_i_type = value; }
        }

        /// <summary>
        ///     源编号
        /// </summary>
        public decimal? I_YUANBH
        {
            get { return m_dec_i_yuanbh; }
            set { m_dec_i_yuanbh = value; }
        }

        /// <summary>
        ///     是否逻辑删除
        /// </summary>
        public decimal? I_JLZT
        {
            get { return m_dec_i_jlzt; }
            set { m_dec_i_jlzt = value; }
        }

        /// <summary>
        ///     处理日期
        /// </summary>
        public DateTime? D_CHULIRQ
        {
            get { return m_DT_d_chulirq; }
            set { m_DT_d_chulirq = value; }
        }

        /// <summary>
        ///     传票日期
        /// </summary>
        public DateTime? D_CHUANPIAORQ
        {
            get { return m_DT_d_chuanpiaorq; }
            set { m_DT_d_chuanpiaorq = value; }
        }

        /// <summary>
        ///     金额
        /// </summary>
        public double? N_JINE
        {
            get { return m_db_n_jine; }
            set { m_db_n_jine = value; }
        }

        /// <summary>
        ///     站点
        /// </summary>
        public string S_ZHANDIANBH
        {
            get { return m_str_s_zhandianbh; }
            set { m_str_s_zhandianbh = value; }
        }

        /// <summary>
        ///     用户号
        /// </summary>
        public string S_YONGHUH
        {
            get { return m_str_s_yonghuh; }
            set { m_str_s_yonghuh = value; }
        }

        /// <summary>
        ///     账务年月
        /// </summary>
        public decimal? I_ZWNY
        {
            get { return m_dec_i_zwny; }
            set { m_dec_i_zwny = value; }
        }

        /// <summary>
        ///     退票/退款原因
        /// </summary>
        public string S_REASON
        {
            get { return m_str_s_reason; }
            set { m_str_s_reason = value; }
        }
    }
}

#endregion

#region EntityProcess

namespace BLL.Access
{
    //using System.Data.OracleClient;

    public class YS_SF_ZHICHUXGProcess
    {
        #region Field

        protected string conn;

        #endregion

        #region Construction

        public YS_SF_ZHICHUXGProcess()
        {
            conn = ConfigHelper.PlatformConnString;
        }

        #endregion

        #region public

        /// <summary>
        ///     根据YS_SF_ZHICHUXG实体添加或者修改YS_SF_ZHICHUXG信息
        /// </summary>
        public bool InsertOrUpdate(YS_SF_ZHICHUXG YS_SF_ZHICHUXG, OracleTransaction Transaction)
        {
            if (YS_SF_ZHICHUXG.I_ZHICHUBH == 0)
                InsertYS_SF_ZHICHUXG(YS_SF_ZHICHUXG, Transaction);
            else
                UpdateYS_SF_ZHICHUXG(YS_SF_ZHICHUXG, Transaction);
            return YS_SF_ZHICHUXG.I_ZHICHUBH == 0 ? false : true;
        }

        /// <summary>
        ///     根据YS_SF_ZHICHUXG实体添加或修改YS_SF_ZHICHUXG信息
        /// </summary>
        public bool InsertOrUpdate(YS_SF_ZHICHUXG YS_SF_ZHICHUXG)
        {
            return InsertOrUpdate(YS_SF_ZHICHUXG, null);
        }


        /// <summary>
        ///     根据YS_SF_ZHICHUXG主键删除YS_SF_ZHICHUXG信息
        /// </summary>
        /// <param name="I_ZHICHUBH"></param>
        public bool DeleteYS_SF_ZHICHUXG(decimal I_ZHICHUBH, OracleTransaction Transaction)
        {
            var spName = "CS_DelYS_SF_ZHICHUXG";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = I_ZHICHUBH;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        ///     根据YS_SF_ZHICHUXG主键删除YS_SF_ZHICHUXG信息
        /// </summary>
        /// <param name="I_ZHICHUBH"></param>
        public bool DeleteYS_SF_ZHICHUXG(decimal I_ZHICHUBH)
        {
            return DeleteYS_SF_ZHICHUXG(I_ZHICHUBH, null);
        }

        /// <summary>
        ///     根据条件删除YS_SF_ZHICHUXG信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteYS_SF_ZHICHUXGsDynamic(string WhereClause, OracleTransaction Transaction)
        {
            var spName = "CS_DelYS_SF_ZHICHUXGsDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = WhereClause;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        ///     根据条件删除YS_SF_ZHICHUXG信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteYS_SF_ZHICHUXGsDynamic(string WhereClause)
        {
            return DeleteYS_SF_ZHICHUXGsDynamic(WhereClause, null);
        }

        /// <summary>
        ///     根据YS_SF_ZHICHUXG主键选择YS_SF_ZHICHUXG信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>YS_SF_ZHICHUXG信息</returns>
        public YS_SF_ZHICHUXG SelectYS_SF_ZHICHUXG(decimal I_ZHICHUBH, OracleTransaction Transaction)
        {
            var spName = "CS_SelYS_SF_ZHICHUXG";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = I_ZHICHUBH;
            OracleDataReader rd;
            if (Transaction == null)
                rd = OracleHelper.ExecuteReader(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                rd = OracleHelper.ExecuteReader(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (rd.Read())
            {
                var YS_SF_ZHICHUXG = PopulateYS_SF_ZHICHUXG(rd);
                rd.Close();
                return YS_SF_ZHICHUXG;
            }
            return null;
        }

        /// <summary>
        ///     根据YS_SF_ZHICHUXG主键选择YS_SF_ZHICHUXG信息
        /// </summary>
        /// <returns>YS_SF_ZHICHUXG信息</returns>
        public YS_SF_ZHICHUXG SelectYS_SF_ZHICHUXG(decimal I_ZHICHUBH)
        {
            return SelectYS_SF_ZHICHUXG(I_ZHICHUBH, null);
        }

        /// <summary>
        ///     选择所有YS_SF_ZHICHUXG信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>所有YS_SF_ZHICHUXG信息</returns>
        public DataTable SelectYS_SF_ZHICHUXGsAll(OracleTransaction Transaction)
        {
            var spName = "CS_SelYS_SF_ZHICHUXGsAll";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }

        /// <summary>
        ///     选择所有YS_SF_ZHICHUXG信息
        /// </summary>
        /// <returns>所有YS_SF_ZHICHUXG信息</returns>
        public DataTable SelectYS_SF_ZHICHUXGsAll()
        {
            return SelectYS_SF_ZHICHUXGsAll(null);
        }

        /// <summary>
        ///     根据条件选择YS_SF_ZHICHUXG信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>YS_SF_ZHICHUXG信息</returns>
        public DataTable SelectYS_SF_ZHICHUXGsDynamic(string WhereClause, string OrderByExpression,
            OracleTransaction Transaction)
        {
            var spName = "CS_SelYS_SF_ZHICHUXGsDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }


        /// <summary>
        ///     根据条件选择YS_SF_ZHICHUXG信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <returns>YS_SF_ZHICHUXG信息</returns>
        public DataTable SelectYS_SF_ZHICHUXGsDynamic(string WhereClause, string OrderByExpression)
        {
            return SelectYS_SF_ZHICHUXGsDynamic(WhereClause, OrderByExpression, null);
        }


        /// <summary>
        ///     根据条件选择YS_SF_ZHICHUXG信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>YS_SF_ZHICHUXG信息</returns>
        public DataTable SelectYS_SF_ZHICHUXGsDynamic(string WhereClause, string OrderByExpression, int PageIndex,
            int PageSize, OracleTransaction Transaction)
        {
            var spName = "CS_SelYS_SF_ZHICHUXGsDynPaged";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            storedParams[2].Value = PageIndex;
            storedParams[3].Value = PageSize;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }


        /// <summary>
        ///     根据条件选择YS_SF_ZHICHUXG信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <returns>YS_SF_ZHICHUXG信息</returns>
        public DataTable SelectYS_SF_ZHICHUXGsDynamic(string WhereClause, string OrderByExpression, int PageIndex,
            int PageSize)
        {
            return SelectYS_SF_ZHICHUXGsDynamic(WhereClause, OrderByExpression, PageIndex, PageSize, null);
        }

        /// <summary>
        ///     根据条件更新YS_SF_ZHICHUXG字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateYS_SF_ZHICHUXGsDynamic(string UpdateValue, string WhereClause, OracleTransaction Transaction)
        {
            var result = 0;
            if (UpdateValue == "" || WhereClause == "")
                return 0;
            var spName = "CS_UpdYS_SF_ZHICHUXGDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            storedParams[0].Value = UpdateValue;
            storedParams[1].Value = WhereClause;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            result = Convert.ToInt32(storedParams[2].Value);
            return result;
        }

        /// <summary>
        ///     根据条件更新YS_SF_ZHICHUXG字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateYS_SF_ZHICHUXGsDynamic(string UpdateValue, string WhereClause)
        {
            return UpdateYS_SF_ZHICHUXGsDynamic(UpdateValue, WhereClause, null);
        }

        #endregion

        #region Private

        private int InsertYS_SF_ZHICHUXG(YS_SF_ZHICHUXG YS_SF_ZHICHUXG, OracleTransaction Transaction)
        {
            var spName = "CS_InsYS_SF_ZHICHUXG";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = YS_SF_ZHICHUXG.I_CHULIR;
            storedParams[1].Value = YS_SF_ZHICHUXG.I_FEIYONGBH;
            storedParams[2].Value = YS_SF_ZHICHUXG.I_Y;
            storedParams[3].Value = YS_SF_ZHICHUXG.I_M;
            storedParams[4].Value = YS_SF_ZHICHUXG.I_TYPE;
            storedParams[5].Value = YS_SF_ZHICHUXG.I_YUANBH;
            storedParams[6].Value = YS_SF_ZHICHUXG.I_JLZT;
            storedParams[7].Value = YS_SF_ZHICHUXG.D_CHULIRQ;
            storedParams[8].Value = YS_SF_ZHICHUXG.D_CHUANPIAORQ;
            storedParams[9].Value = YS_SF_ZHICHUXG.N_JINE;
            storedParams[10].Value = YS_SF_ZHICHUXG.S_ZHANDIANBH;
            storedParams[11].Value = YS_SF_ZHICHUXG.S_YONGHUH;
            storedParams[12].Value = YS_SF_ZHICHUXG.I_ZWNY;
            storedParams[13].Value = YS_SF_ZHICHUXG.S_REASON;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            YS_SF_ZHICHUXG.I_ZHICHUBH = Convert.ToInt32(storedParams[14].Value);
            return result;
        }

        private bool UpdateYS_SF_ZHICHUXG(YS_SF_ZHICHUXG YS_SF_ZHICHUXG, OracleTransaction Transaction)
        {
            var spName = "CS_UpdYS_SF_ZHICHUXG";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = YS_SF_ZHICHUXG.I_CHULIR;
            storedParams[1].Value = YS_SF_ZHICHUXG.I_FEIYONGBH;
            storedParams[2].Value = YS_SF_ZHICHUXG.I_Y;
            storedParams[3].Value = YS_SF_ZHICHUXG.I_M;
            storedParams[4].Value = YS_SF_ZHICHUXG.I_TYPE;
            storedParams[5].Value = YS_SF_ZHICHUXG.I_YUANBH;
            storedParams[6].Value = YS_SF_ZHICHUXG.I_JLZT;
            storedParams[7].Value = YS_SF_ZHICHUXG.D_CHULIRQ;
            storedParams[8].Value = YS_SF_ZHICHUXG.D_CHUANPIAORQ;
            storedParams[9].Value = YS_SF_ZHICHUXG.N_JINE;
            storedParams[10].Value = YS_SF_ZHICHUXG.S_ZHANDIANBH;
            storedParams[11].Value = YS_SF_ZHICHUXG.S_YONGHUH;
            storedParams[12].Value = YS_SF_ZHICHUXG.I_ZWNY;
            storedParams[13].Value = YS_SF_ZHICHUXG.S_REASON;
            storedParams[14].Value = YS_SF_ZHICHUXG.I_ZHICHUBH;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }


        private YS_SF_ZHICHUXG PopulateYS_SF_ZHICHUXG(IDataReader dr)
        {
            var YS_SF_ZHICHUXG = new YS_SF_ZHICHUXG();
            YS_SF_ZHICHUXG.I_ZHICHUBH = dr["I_ZHICHUBH"] == DBNull.Value ? 0 : (decimal) dr["I_ZHICHUBH"];
            YS_SF_ZHICHUXG.I_CHULIR = dr["I_CHULIR"] == DBNull.Value ? null : (decimal?) dr["I_CHULIR"];
            YS_SF_ZHICHUXG.I_FEIYONGBH = dr["I_FEIYONGBH"] == DBNull.Value ? null : (decimal?) dr["I_FEIYONGBH"];
            YS_SF_ZHICHUXG.I_Y = dr["I_Y"] == DBNull.Value ? null : (decimal?) dr["I_Y"];
            YS_SF_ZHICHUXG.I_M = dr["I_M"] == DBNull.Value ? null : (decimal?) dr["I_M"];
            YS_SF_ZHICHUXG.I_TYPE = dr["I_TYPE"] == DBNull.Value ? null : (decimal?) dr["I_TYPE"];
            YS_SF_ZHICHUXG.I_YUANBH = dr["I_YUANBH"] == DBNull.Value ? null : (decimal?) dr["I_YUANBH"];
            YS_SF_ZHICHUXG.I_JLZT = dr["I_JLZT"] == DBNull.Value ? null : (decimal?) dr["I_JLZT"];
            YS_SF_ZHICHUXG.D_CHULIRQ = dr["D_CHULIRQ"] == DBNull.Value ? null : (DateTime?) dr["D_CHULIRQ"];
            YS_SF_ZHICHUXG.D_CHUANPIAORQ = dr["D_CHUANPIAORQ"] == DBNull.Value ? null : (DateTime?) dr["D_CHUANPIAORQ"];
            YS_SF_ZHICHUXG.N_JINE = dr["N_JINE"] == DBNull.Value ? null : (double?) dr["N_JINE"];
            YS_SF_ZHICHUXG.S_ZHANDIANBH = dr["S_ZHANDIANBH"] == DBNull.Value ? null : (string) dr["S_ZHANDIANBH"];
            YS_SF_ZHICHUXG.S_YONGHUH = dr["S_YONGHUH"] == DBNull.Value ? null : (string) dr["S_YONGHUH"];
            YS_SF_ZHICHUXG.I_ZWNY = dr["I_ZWNY"] == DBNull.Value ? null : (decimal?) dr["I_ZWNY"];
            YS_SF_ZHICHUXG.S_REASON = dr["S_REASON"] == DBNull.Value ? null : (string) dr["S_REASON"];
            return YS_SF_ZHICHUXG;
        }


        private void AddRowNumber(DataTable dt)
        {
            dt.Columns.Add(new DataColumn("RowNumber", typeof(int)));
            for (var i = 0; i < dt.Rows.Count; i++)
                dt.Rows[i][dt.Columns.Count - 1] = i + 1;
        }

        #endregion
    }
}

#endregion